
using System;
using System.Reflection;
using System.Collections;
using System.Collections.Generic;
using Evaluant.Uss;
using Evaluant.Uss.ObjectContext;

		

namespace Northwind
{
		
	public partial interface ICustomer
	{
		string Id { get; set; }
		System.String CompanyName { get; set; }
		System.String ContactName { get; set; }
		System.String City { get; set; }
		
		IEnumerable<IOrder>  Orders { get; }

	}
	
  
  [Serializable]
  public partial class CustomerCollection : IPersistableCollection<Customer>
	{
		public CustomerCollection() : base()
    {
    }

    public CustomerCollection (ObjectContext persistenceManager, IPersistable parent, string role, IEnumerable<Customer> data): base(persistenceManager, parent, role, data)
    {
    }
	}

	[Serializable]
	public partial class Customer :  IPersistable, ICustomer 
	{		
	
		[NonSerialized]
		protected Entity _Entity;
		
		[NonSerialized]
		protected ObjectContext _PersistenceManager;
		
		Entity IPersistable.Entity
		{
			get
			{
				return _Entity;
			}
			set
			{
				_Entity = value;
			}
		}
		
		ObjectContext IPersistable.ObjectContext
		{
			get
			{
				return _PersistenceManager;
			}
			set
			{
				_PersistenceManager = value;
			}
		}
		
		public string Id
		{
			get
			{
				return _Entity.Id;
			}
			set
			{
				_Entity.Id = value;
			}
		}
		
		~Customer()
		{
			if(_PersistenceManager != null)
				_PersistenceManager.RemoveFromCache(this);
		}
	
		void IPersistable.TrackChildren()
		{
			// if the object is not tracked there is nothing to do
			if(_PersistenceManager == null)
				return;
	
			if(_Orders != null)
				_PersistenceManager.TrackObject(_Orders);
		
		}
		
	
    protected System.String _CompanyName;

    public System.String CompanyName
    {
      get
      {
        if(_Entity != null && !_Entity.IsNull("CompanyName"))
          _CompanyName = (System.String)this._Entity["CompanyName"];
          
        return _CompanyName;
      }

      set
      {
        _CompanyName = value;
        if(_Entity != null)
			this._Entity["CompanyName"] = value;
      }
    }
    
    protected System.String _ContactName;

    public System.String ContactName
    {
      get
      {
        if(_Entity != null && !_Entity.IsNull("ContactName"))
          _ContactName = (System.String)this._Entity["ContactName"];
          
        return _ContactName;
      }

      set
      {
        _ContactName = value;
        if(_Entity != null)
			this._Entity["ContactName"] = value;
      }
    }
    
    protected System.String _City;

    public System.String City
    {
      get
      {
        if(_Entity != null && !_Entity.IsNull("City"))
          _City = (System.String)this._Entity["City"];
          
        return _City;
      }

      set
      {
        _City = value;
        if(_Entity != null)
			this._Entity["City"] = value;
      }
    }
    
    protected OrderCollection _Orders;

    public OrderCollection Orders
    {
      get
      {
        if(_Orders == null)
        {
          // Inferred relationships
          EntitySet entities = _Entity.GetEntitySet("Orders");
          List<Order> items = entities.Count == 0 ? null : _PersistenceManager.LoadWithEntities<Order>(entities);

          _Orders = new OrderCollection(_PersistenceManager, this, "Orders", items);
        }
        return _Orders;
      }

      set // Defined for Serializable() compatibility only
      {
        _Orders = value;
      }
    }

		IEnumerable<IOrder> ICustomer.Orders
		{	                
			get 
			{ 
				foreach(IOrder item in Orders) 
					yield return item;
			}
		}
	
		public Customer ()
		{
			
			this._Entity = new Entity(ObjectContext.ConvertNamespaceDomainToEuss(this.GetType().FullName));
		}

		public Customer (Entity e)
		{
			this._Entity = e;
		}

		[Serializable]
		public class ParentRelationships
		{
			private IPersistable _Owner;
	
			public ParentRelationships()
			{
			}
			
			public ParentRelationships(IPersistable o)
			{
				_Owner = o;
			}
		
		}
	}
	
	public partial interface IOrder
	{
		string Id { get; set; }
		System.DateTime OrderDate { get; set; }
		System.String ShipName { get; set; }
		System.Int32 ShipVia { get; set; }
		
	}
	
  
  [Serializable]
  public partial class OrderCollection : IPersistableCollection<Order>
	{
		public OrderCollection() : base()
    {
    }

    public OrderCollection (ObjectContext persistenceManager, IPersistable parent, string role, IEnumerable<Order> data): base(persistenceManager, parent, role, data)
    {
    }
	}

	[Serializable]
	public partial class Order :  IPersistable, IOrder 
	{		
	
		[NonSerialized]
		protected Entity _Entity;
		
		[NonSerialized]
		protected ObjectContext _PersistenceManager;
		
		Entity IPersistable.Entity
		{
			get
			{
				return _Entity;
			}
			set
			{
				_Entity = value;
			}
		}
		
		ObjectContext IPersistable.ObjectContext
		{
			get
			{
				return _PersistenceManager;
			}
			set
			{
				_PersistenceManager = value;
			}
		}
		
		public string Id
		{
			get
			{
				return _Entity.Id;
			}
			set
			{
				_Entity.Id = value;
			}
		}
		
		~Order()
		{
			if(_PersistenceManager != null)
				_PersistenceManager.RemoveFromCache(this);
		}
	
		void IPersistable.TrackChildren()
		{
			// if the object is not tracked there is nothing to do
			if(_PersistenceManager == null)
				return;
	
		}
		
	
    protected System.DateTime _OrderDate;

    public System.DateTime OrderDate
    {
      get
      {
        if(_Entity != null && !_Entity.IsNull("OrderDate"))
          _OrderDate = (System.DateTime)this._Entity["OrderDate"];
          
        return _OrderDate;
      }

      set
      {
        _OrderDate = value;
        if(_Entity != null)
			this._Entity["OrderDate"] = value;
      }
    }
    
    protected System.String _ShipName;

    public System.String ShipName
    {
      get
      {
        if(_Entity != null && !_Entity.IsNull("ShipName"))
          _ShipName = (System.String)this._Entity["ShipName"];
          
        return _ShipName;
      }

      set
      {
        _ShipName = value;
        if(_Entity != null)
			this._Entity["ShipName"] = value;
      }
    }
    
    protected System.Int32 _ShipVia;

    public System.Int32 ShipVia
    {
      get
      {
        if(_Entity != null && !_Entity.IsNull("ShipVia"))
          _ShipVia = (System.Int32)this._Entity["ShipVia"];
          
        return _ShipVia;
      }

      set
      {
        _ShipVia = value;
        if(_Entity != null)
			this._Entity["ShipVia"] = value;
      }
    }
    
		public Order ()
		{
			
			this._Entity = new Entity(ObjectContext.ConvertNamespaceDomainToEuss(this.GetType().FullName));
		}

		public Order (Entity e)
		{
			this._Entity = e;
		}

		[Serializable]
		public class ParentRelationships
		{
			private IPersistable _Owner;
	
			public ParentRelationships()
			{
			}
			
			public ParentRelationships(IPersistable o)
			{
				_Owner = o;
			}
		
		}
	}

}
